/*
 *  sys.c
 *
 *  Created on: 2010-5-24
 *      Author: liuyond
 */
#include "cpu.h"

void HLT(cpu_t *cpu, instruction_t *i)
{
	cpu->status |= CPU_HALT;
}

void CMC(cpu_t *cpu, instruction_t *i)
{
	cpu_set_flag(cpu, CF, !cpu_get_flag(cpu, CF));
}

void CLC(cpu_t *cpu, instruction_t *i)
{
	cpu_set_flag(cpu, CF, 0);
}

void STC(cpu_t *cpu, instruction_t *i)
{
	cpu_set_flag(cpu, CF, 1);
}

void CLI(cpu_t *cpu, instruction_t *i)
{
	cpu_set_flag(cpu, IF, 0);
}

void STI(cpu_t *cpu, instruction_t *i)
{
	cpu_set_flag(cpu, IF, 1);
}

void CLD(cpu_t *cpu, instruction_t *i)
{
	cpu_set_flag(cpu, DF, 0);
}

void STD(cpu_t *cpu, instruction_t *i)
{
	cpu_set_flag(cpu, DF, 1);
}


void SAHF(cpu_t *cpu, instruction_t *i)
{
	int tmp = cpu->flags & 0xFF;
	cpu_set_regb(cpu, AH, tmp);
}

void LAHF(cpu_t *cpu, instruction_t *i)
{
	int tmp = cpu->flags & (~0xFF);
	tmp |= cpu_get_regb(cpu, AH);
	cpu->flags = tmp;
}

void NOP(cpu_t *cpu, instruction_t *i)
{
	// no operation, just occupy one byte
}

void WAIT(cpu_t *cpu, instruction_t *i)
{
	// no operation, just occupy one byte
}
